package team.xiaobaiya.gptchatrobot.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import team.xiaobaiya.gptchatrobot.entity.body.UserKeyBody;
import team.xiaobaiya.gptchatrobot.entity.database.UserInfo;
import team.xiaobaiya.gptchatrobot.service.UserInfoService;
import team.xiaobaiya.gptchatrobot.util.Resp;
import team.xiaobaiya.gptchatrobot.util.RespCodeEnum;

/**
 * @author Feng Yingnan
 * @since 2023/12/15
 */
@Slf4j
@CrossOrigin
@RestController
@RequestMapping("user")
public class UserController {

    private final UserInfoService userInfoService;

    public UserController(UserInfoService userInfoService) {
        this.userInfoService = userInfoService;
    }


    @PostMapping("/info")
    public Resp<UserInfo> userInfo(@RequestBody UserKeyBody body) {
        if (body.getUserKey() == null || body.getUserKey().isEmpty()) {
            return Resp.error(RespCodeEnum.REQUEST_PARAM_ERROR, "UserKey为空");
        }
        UserInfo userInfo = userInfoService.selectByUserKey(body.getUserKey());
        if (userInfo == null) {
            return Resp.ok();
        }
        return Resp.ok(userInfo);
    }



}
